package com.yun.algorithmproblem.leetcode;

public class Leetcode922 {

    public int[] sortArrayByParityII(int[] nums) {
        int odd= nums.length-1;
        int even=odd-1;
        while (even>=0){
            if(nums[0]%2==0){
                swap(nums,0,even);
                even-=2;
            }else {
                swap(nums,0,odd);
                odd-=2;
            }
        }
        return nums;
    }

    private void swap(int[] nums,int i,int j){
        int temp=nums[i];
        nums[i]=nums[j];
        nums[j]=temp;
    }
}
